/*
 * IsaSimView.java
 */
package isasim;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import java.io.File;

/**
 * The application's main frame.
 */
public class IsaSimView extends FrameView {

    Cpu cpu = Cpu.getCpu();
    int page = 0;
    boolean dec = true;

    public IsaSimView(SingleFrameApplication app) {
        super(app);

        initComponents();
        resetRegisters();
        initPageCombo();
        initMemoryDisplay(page, dec);
        memoryList.setFixedCellHeight(18);







        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = IsaSim.getApplication().getMainFrame();
            aboutBox = new IsaSimAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        IsaSim.getApplication().show(aboutBox);
    }

    public void resetRegisters() {

        r0TxtField.setText(Integer.toString(cpu.registers.getValue(0)));
        r1TxtField.setText(Integer.toString(cpu.registers.getValue(1)));
        r2TxtField.setText(Integer.toString(cpu.registers.getValue(2)));
        r3TxtField.setText(Integer.toString(cpu.registers.getValue(3)));
        r4TxtField.setText(Integer.toString(cpu.registers.getValue(4)));
        r5TxtField.setText(Integer.toString(cpu.registers.getValue(5)));
        r6TxtField.setText(Integer.toString(cpu.registers.getValue(6)));
        r7TxtField.setText(Integer.toString(cpu.registers.getValue(7)));
        r8TxtField.setText(Integer.toString(cpu.registers.getValue(8)));
        r9TxtField.setText(Integer.toString(cpu.registers.getValue(9)));
        r10TxtField.setText(Integer.toString(cpu.registers.getValue(10)));
        r11TxtField.setText(Integer.toString(cpu.registers.getValue(11)));
        r12TxtField.setText(Integer.toString(cpu.registers.getValue(12)));
        r13TxtField.setText(Integer.toString(cpu.registers.getValue(13)));
        r14TxtField.setText(Integer.toString(cpu.registers.getValue(14)));
        r15TxtField.setText(Integer.toString(cpu.registers.getValue(15)));
    }

    public void refreshRegisters() {

        if (dec) {
            resetRegisters();
        } else {

            r0TxtField.setText(Integer.toHexString(cpu.registers.getValue(0)));
            r1TxtField.setText(Integer.toHexString(cpu.registers.getValue(1)));
            r2TxtField.setText(Integer.toHexString(cpu.registers.getValue(2)));
            r3TxtField.setText(Integer.toHexString(cpu.registers.getValue(3)));
            r4TxtField.setText(Integer.toHexString(cpu.registers.getValue(4)));
            r5TxtField.setText(Integer.toHexString(cpu.registers.getValue(5)));
            r6TxtField.setText(Integer.toHexString(cpu.registers.getValue(6)));
            r7TxtField.setText(Integer.toHexString(cpu.registers.getValue(7)));
            r8TxtField.setText(Integer.toHexString(cpu.registers.getValue(8)));
            r9TxtField.setText(Integer.toHexString(cpu.registers.getValue(9)));
            r10TxtField.setText(Integer.toHexString(cpu.registers.getValue(10)));
            r11TxtField.setText(Integer.toHexString(cpu.registers.getValue(11)));
            r12TxtField.setText(Integer.toHexString(cpu.registers.getValue(12)));
            r13TxtField.setText(Integer.toHexString(cpu.registers.getValue(13)));
            r14TxtField.setText(Integer.toHexString(cpu.registers.getValue(14)));
            r15TxtField.setText(Integer.toHexString(cpu.registers.getValue(15)));
        }
    }

    public void initMemoryDisplay(int currentPage, boolean decimal) {
        int[][] tempPage = cpu.memory.getPage(currentPage);
        String[] displayMemory = new String[cpu.memory.getPage(currentPage).length];
        String formatAddress = "";
        String formatData = "";

        if (!decimal) {
            for (int x = 0; x < displayMemory.length; x++) {
                for (int y = 0; y < 8; y++) {
                    formatAddress = Integer.toHexString(tempPage[x][0]);
                    formatData = Integer.toHexString(tempPage[x][1]);
                    while (formatAddress.length() < 8) {
                        formatAddress = "0" + formatAddress;
                    }
                    formatAddress.toUpperCase();
                    while (formatData.length() < 8) {
                        formatData = "0" + formatData;
                    }
                    formatData.toUpperCase();
                }



                displayMemory[x] = "0x" + formatAddress + "                       0x" + formatData;
                //System.out.println(displayMemory[x] +" "+ "Item" + x);

            }
        } else {
            for (int x = 0; x < displayMemory.length; x++) {
                for (int y = 0; y < 10; y++) {
                    formatAddress = "" + tempPage[x][0];
                    formatData = "" + tempPage[x][1];



                    while (formatAddress.length() < 10) {
                        formatAddress = "0" + formatAddress;
                    }

                    if (formatData.charAt(0) == 45) {
                        break;
                    } else {
                        while (formatData.length() < 10) {
                            formatData = "0" + formatData;
                        }
                    }
                }



                displayMemory[x] = formatAddress + "                        " + formatData;
                //System.out.println(displayMemory[x] +" "+ "Item" + x);
            }

        }
        memoryList.setListData(displayMemory);
        memoryList.updateUI();
    }

    public void initPageCombo() {

        for (int i = 0; i < cpu.memory.addressList.length; i++) {
            pageCombo.addItem(cpu.memory.addressList[i]);
        }
    }

    private int hex2Dec(String input) {
        int decimal = 0;
        for (int i = 0; i < input.length(); i++) {
            int digit = hexValue(input.charAt(i));
            if (digit == -1) {
                return 0;//need to fiz this
            }
            decimal = 16 * decimal + digit;
        }
        return decimal;
    }

    static int hexValue(char ch) {
        // Returns the hexadecimal value of ch, or returns
        // -1 if ch is not one of the hexadecimal digits.
        switch (ch) {
            case '0':
                return 0;
            case '1':
                return 1;
            case '2':
                return 2;
            case '3':
                return 3;
            case '4':
                return 4;
            case '5':
                return 5;
            case '6':
                return 6;
            case '7':
                return 7;
            case '8':
                return 8;
            case '9':
                return 9;
            case 'a':
            case 'A':
                return 10;
            case 'b':
            case 'B':
                return 11;
            case 'c':
            case 'C':
                return 12;
            case 'd':
            case 'D':
                return 13;
            case 'e':
            case 'E':
                return 14;
            case 'f':
            case 'F':
                return 15;
            default:
                return -1;

        }  // end hexValue()


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        exportBtn = new javax.swing.JButton();
        importBtn = new javax.swing.JButton();
        representationCombo = new javax.swing.JComboBox();
        pageCombo = new javax.swing.JComboBox();
        elapsedLbl = new javax.swing.JLabel();
        resetBtn = new javax.swing.JButton();
        stepOneBtn = new javax.swing.JButton();
        r0TxtField = new javax.swing.JTextField();
        r1TxtField = new javax.swing.JTextField();
        r2TxtField = new javax.swing.JTextField();
        r3TxtField = new javax.swing.JTextField();
        r4TxtField = new javax.swing.JTextField();
        r6TxtField = new javax.swing.JTextField();
        r7TxtField = new javax.swing.JTextField();
        r5TxtField = new javax.swing.JTextField();
        r8TxtField = new javax.swing.JTextField();
        r10TxtField = new javax.swing.JTextField();
        r11TxtField = new javax.swing.JTextField();
        r9TxtField = new javax.swing.JTextField();
        r12TxtField = new javax.swing.JTextField();
        r14TxtField = new javax.swing.JTextField();
        r15TxtField = new javax.swing.JTextField();
        r13TxtField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        memoryList = new javax.swing.JList();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        jScrollPane2 = new javax.swing.JScrollPane();
        jEditorPane1 = new javax.swing.JEditorPane();
        memoryDialog = new javax.swing.JDialog();
        okBtn = new javax.swing.JButton();
        cancelBtn = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        memoryAddressChangerLabel = new javax.swing.JLabel();
        memoryChangerTxtField = new javax.swing.JTextField();

        mainPanel.setName("mainPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(isasim.IsaSim.class).getContext().getResourceMap(IsaSimView.class);
        exportBtn.setText(resourceMap.getString("exportBtn.text")); // NOI18N
        exportBtn.setToolTipText(resourceMap.getString("exportBtn.toolTipText")); // NOI18N
        exportBtn.setName("exportBtn"); // NOI18N
        exportBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                exportBtnMouseClicked(evt);
            }
        });

        importBtn.setText(resourceMap.getString("importBtn.text")); // NOI18N
        importBtn.setToolTipText(resourceMap.getString("importBtn.toolTipText")); // NOI18N
        importBtn.setName("importBtn"); // NOI18N
        importBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                importBtnMouseClicked(evt);
            }
        });

        representationCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Decimal", "Hexadecimal" }));
        representationCombo.setToolTipText(resourceMap.getString("representationCombo.toolTipText")); // NOI18N
        representationCombo.setName("representationCombo"); // NOI18N
        representationCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                representationComboActionPerformed(evt);
            }
        });

        pageCombo.setToolTipText(resourceMap.getString("pageCombo.toolTipText")); // NOI18N
        pageCombo.setName("pageCombo"); // NOI18N
        pageCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pageComboActionPerformed(evt);
            }
        });

        elapsedLbl.setText(resourceMap.getString("elapsedLbl.text")); // NOI18N
        elapsedLbl.setName("elapsedLbl"); // NOI18N

        resetBtn.setText(resourceMap.getString("resetBtn.text")); // NOI18N
        resetBtn.setName("resetBtn"); // NOI18N

        stepOneBtn.setText(resourceMap.getString("stepOneBtn.text")); // NOI18N
        stepOneBtn.setName("stepOneBtn"); // NOI18N

        r0TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r0TxtField.setText(resourceMap.getString("r0TxtField.text")); // NOI18N
        r0TxtField.setName("r0TxtField"); // NOI18N
        r0TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r0TxtFieldActionPerformed(evt);
            }
        });

        r1TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r1TxtField.setText(resourceMap.getString("r1TxtField.text")); // NOI18N
        r1TxtField.setName("r1TxtField"); // NOI18N
        r1TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r1TxtFieldActionPerformed(evt);
            }
        });

        r2TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r2TxtField.setText(resourceMap.getString("r2TxtField.text")); // NOI18N
        r2TxtField.setName("r2TxtField"); // NOI18N
        r2TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r2TxtFieldActionPerformed(evt);
            }
        });

        r3TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r3TxtField.setText(resourceMap.getString("r3TxtField.text")); // NOI18N
        r3TxtField.setName("r3TxtField"); // NOI18N
        r3TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r3TxtFieldActionPerformed(evt);
            }
        });

        r4TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r4TxtField.setText(resourceMap.getString("r4TxtField.text")); // NOI18N
        r4TxtField.setName("r4TxtField"); // NOI18N
        r4TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r4TxtFieldActionPerformed(evt);
            }
        });

        r6TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r6TxtField.setText(resourceMap.getString("r6TxtField.text")); // NOI18N
        r6TxtField.setName("r6TxtField"); // NOI18N
        r6TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r6TxtFieldActionPerformed(evt);
            }
        });

        r7TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r7TxtField.setText(resourceMap.getString("r7TxtField.text")); // NOI18N
        r7TxtField.setName("r7TxtField"); // NOI18N
        r7TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r7TxtFieldActionPerformed(evt);
            }
        });

        r5TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r5TxtField.setText(resourceMap.getString("r5TxtField.text")); // NOI18N
        r5TxtField.setName("r5TxtField"); // NOI18N
        r5TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r5TxtFieldActionPerformed(evt);
            }
        });

        r8TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r8TxtField.setText(resourceMap.getString("r8TxtField.text")); // NOI18N
        r8TxtField.setName("r8TxtField"); // NOI18N
        r8TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r8TxtFieldActionPerformed(evt);
            }
        });

        r10TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r10TxtField.setText(resourceMap.getString("r10TxtField.text")); // NOI18N
        r10TxtField.setName("r10TxtField"); // NOI18N
        r10TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r10TxtFieldActionPerformed(evt);
            }
        });

        r11TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r11TxtField.setText(resourceMap.getString("r11TxtField.text")); // NOI18N
        r11TxtField.setName("r11TxtField"); // NOI18N
        r11TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r11TxtFieldActionPerformed(evt);
            }
        });

        r9TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r9TxtField.setText(resourceMap.getString("r9TxtField.text")); // NOI18N
        r9TxtField.setName("r9TxtField"); // NOI18N
        r9TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r9TxtFieldActionPerformed(evt);
            }
        });

        r12TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r12TxtField.setText(resourceMap.getString("r12TxtField.text")); // NOI18N
        r12TxtField.setName("r12TxtField"); // NOI18N
        r12TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r12TxtFieldActionPerformed(evt);
            }
        });

        r14TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r14TxtField.setText(resourceMap.getString("r14TxtField.text")); // NOI18N
        r14TxtField.setName("r14TxtField"); // NOI18N
        r14TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r14TxtFieldActionPerformed(evt);
            }
        });

        r15TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r15TxtField.setText(resourceMap.getString("r15TxtField.text")); // NOI18N
        r15TxtField.setName("r15TxtField"); // NOI18N
        r15TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r15TxtFieldActionPerformed(evt);
            }
        });

        r13TxtField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        r13TxtField.setText(resourceMap.getString("r13TxtField.text")); // NOI18N
        r13TxtField.setName("r13TxtField"); // NOI18N
        r13TxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r13TxtFieldActionPerformed(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        memoryList.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        memoryList.setFont(resourceMap.getFont("memoryList.font")); // NOI18N
        memoryList.setName("memoryList"); // NOI18N
        memoryList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                memoryListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(memoryList);

        jLabel18.setText(resourceMap.getString("jLabel18.text")); // NOI18N
        jLabel18.setName("jLabel18"); // NOI18N

        jLabel19.setText(resourceMap.getString("jLabel19.text")); // NOI18N
        jLabel19.setName("jLabel19"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(exportBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(importBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pageCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(stepOneBtn))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                        .addComponent(resetBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(elapsedLbl)
                        .addGap(144, 144, 144))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel4)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 141, Short.MAX_VALUE)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel8)))
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addComponent(r2TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel10))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addComponent(r0TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel9))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addComponent(r14TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel16))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addComponent(r4TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel11))
                            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                                    .addComponent(r8TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel13))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                                    .addComponent(r6TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jLabel12)))
                            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                                    .addComponent(r12TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel15))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                                    .addComponent(r10TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jLabel14))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(representationCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(r3TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(r1TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(r7TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(r13TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(r15TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(r9TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(r11TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(r5TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(1373, 1373, 1373))
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(126, 126, 126)
                .addComponent(jLabel18)
                .addGap(102, 102, 102)
                .addComponent(jLabel19)
                .addContainerGap(1782, Short.MAX_VALUE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(exportBtn)
                    .addComponent(importBtn)
                    .addComponent(representationCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pageCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(elapsedLbl)
                    .addComponent(resetBtn)
                    .addComponent(stepOneBtn))
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r0TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r2TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r4TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r6TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r8TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel5))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r10TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel6))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r12TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel7))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r14TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel8)))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r1TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel9))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r3TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel10))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r5TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel11))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r7TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel12))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r9TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel13))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r11TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel14))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r13TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel15))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(r15TxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel16)))))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel18)
                            .addComponent(jLabel19))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(86, 86, 86))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        fileMenu.add(jMenuItem1);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(isasim.IsaSim.class).getContext().getActionMap(IsaSimView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 958, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 788, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jEditorPane1.setName("jEditorPane1"); // NOI18N
        jScrollPane2.setViewportView(jEditorPane1);

        memoryDialog.setTitle(resourceMap.getString("memoryDialog.title")); // NOI18N
        memoryDialog.setBounds(new java.awt.Rectangle(300, 300, 0, 0));
        memoryDialog.setMinimumSize(new java.awt.Dimension(294, 180));
        memoryDialog.setName("memoryDialog"); // NOI18N
        memoryDialog.setResizable(false);
        memoryDialog.getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        okBtn.setText(resourceMap.getString("okBtn.text")); // NOI18N
        okBtn.setName("okBtn"); // NOI18N
        okBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                okBtnMouseClicked(evt);
            }
        });
        memoryDialog.getContentPane().add(okBtn, new org.netbeans.lib.awtextra.AbsoluteConstraints(45, 93, 65, -1));

        cancelBtn.setText(resourceMap.getString("cancelBtn.text")); // NOI18N
        cancelBtn.setName("cancelBtn"); // NOI18N
        cancelBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cancelBtnMouseClicked(evt);
            }
        });
        memoryDialog.getContentPane().add(cancelBtn, new org.netbeans.lib.awtextra.AbsoluteConstraints(176, 93, -1, -1));

        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N
        memoryDialog.getContentPane().add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(45, 19, -1, -1));

        memoryAddressChangerLabel.setText(resourceMap.getString("memoryAddressChangerLabel.text")); // NOI18N
        memoryAddressChangerLabel.setName("memoryAddressChangerLabel"); // NOI18N
        memoryDialog.getContentPane().add(memoryAddressChangerLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(118, 41, -1, 10));

        memoryChangerTxtField.setText(resourceMap.getString("memoryChangerTxtField.text")); // NOI18N
        memoryChangerTxtField.setName("memoryChangerTxtField"); // NOI18N
        memoryDialog.getContentPane().add(memoryChangerTxtField, new org.netbeans.lib.awtextra.AbsoluteConstraints(45, 62, 195, -1));

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void r0TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r0TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(0, hex2Dec(r0TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(0, r0TxtField.getText());
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r0TxtFieldActionPerformed

    private void r1TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r1TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(1, hex2Dec(r1TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(1, r1TxtField.getText());
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r1TxtFieldActionPerformed

    private void r2TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r2TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(2, hex2Dec(r2TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(2, r2TxtField.getText());
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r2TxtFieldActionPerformed

    private void r3TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r3TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(3, hex2Dec(r3TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(3, r3TxtField.getText());        // TODO add your handling code here:
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r3TxtFieldActionPerformed

    private void r4TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r4TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(4, hex2Dec(r4TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(4, r4TxtField.getText());
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r4TxtFieldActionPerformed

    private void r5TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r5TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(5, hex2Dec(r5TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(5, r5TxtField.getText());
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r5TxtFieldActionPerformed

    private void r6TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r6TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(6, hex2Dec(r6TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(6, r6TxtField.getText());
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r6TxtFieldActionPerformed

    private void r7TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r7TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(7, hex2Dec(r7TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(7, r7TxtField.getText());
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r7TxtFieldActionPerformed

    private void r8TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r8TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(8, hex2Dec(r8TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(8, r8TxtField.getText());
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r8TxtFieldActionPerformed

    private void r9TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r9TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(9, hex2Dec(r9TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(9, r9TxtField.getText());
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r9TxtFieldActionPerformed

    private void r10TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r10TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(10, hex2Dec(r10TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(10, r10TxtField.getText());
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r10TxtFieldActionPerformed

    private void r11TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r11TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(11, hex2Dec(r11TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(11, r11TxtField.getText());
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r11TxtFieldActionPerformed

    private void r12TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r12TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(12, hex2Dec(r12TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(12, r12TxtField.getText());
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r12TxtFieldActionPerformed

    private void r13TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r13TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(13, hex2Dec(r13TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(13, r13TxtField.getText());
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r13TxtFieldActionPerformed

    private void r14TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r14TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(14, hex2Dec(r14TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(14, r14TxtField.getText());
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r14TxtFieldActionPerformed

    private void r15TxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r15TxtFieldActionPerformed
        if (!dec) {
            cpu.registers.setValue(15, hex2Dec(r15TxtField.getText()));
            refreshRegisters();
            mainPanel.grabFocus();

        } else {
            cpu.registers.setValue(15, r15TxtField.getText());
            refreshRegisters();
            mainPanel.grabFocus();
        }
    }//GEN-LAST:event_r15TxtFieldActionPerformed

    private void memoryListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_memoryListMouseClicked
        if (evt.getClickCount() == 2) {
            // int index = memoryList.locationToIndex(evt.getPoint());
            memoryAddressChangerLabel.setText(memoryList.getSelectedValue().toString().substring(0, 10));
            memoryDialog.setVisible(true);
            memoryChangerTxtField.grabFocus();

        }
        // TODO add your handling code here:
    }//GEN-LAST:event_memoryListMouseClicked

    private void okBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_okBtnMouseClicked

        int parsed;
        
        if (dec){
            parsed = Integer.parseInt(memoryChangerTxtField.getText());
            cpu.memory.setValue(memoryAddressChangerLabel.getText(), parsed);
        }
        else{
            parsed = hex2Dec(memoryChangerTxtField.getText());
            cpu.memory.setValue(Integer.toString(hex2Dec(memoryAddressChangerLabel.getText().substring(3,10))), parsed);
        }

        

        System.out.println(memoryAddressChangerLabel.getText());
        System.out.println(parsed);
        memoryDialog.setVisible(false);
        initMemoryDisplay(page, dec);
        memoryChangerTxtField.setText("");
    }//GEN-LAST:event_okBtnMouseClicked

    private void cancelBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cancelBtnMouseClicked
        memoryChangerTxtField.setText("");
        memoryDialog.setVisible(false);

    }//GEN-LAST:event_cancelBtnMouseClicked

    private void pageComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pageComboActionPerformed
        page = pageCombo.getSelectedIndex();
        initMemoryDisplay(page, dec);
    }//GEN-LAST:event_pageComboActionPerformed

    private void representationComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_representationComboActionPerformed
        if (representationCombo.getSelectedIndex() == 0) {
            dec = true;
        } else {
            dec = false;
        }
       // System.out.println(representationCombo.getSelectedIndex());
        initMemoryDisplay(page, dec);
        refreshRegisters();
    }//GEN-LAST:event_representationComboActionPerformed

    private void exportBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_exportBtnMouseClicked
        javax.swing.JFileChooser chooser = new javax.swing.JFileChooser();


        chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {

            public boolean accept(File f) {
                return f.getName().toLowerCase().endsWith(".txt")
                        || f.isDirectory();
            }

            public String getDescription() {
                return "txt file";
            }
        });

        int r = chooser.showSaveDialog(new JFrame());
        if (r == javax.swing.JFileChooser.APPROVE_OPTION) {
            File f;
            f = chooser.getSelectedFile();
            System.out.println(f.getAbsolutePath());
            cpu.memory.writeToDisk(f.getAbsolutePath());
        }

    }//GEN-LAST:event_exportBtnMouseClicked

    private void importBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_importBtnMouseClicked
        javax.swing.JFileChooser chooser = new javax.swing.JFileChooser();
        //chooser.setCurrentDirectory(new File("."));

        chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {

            public boolean accept(File f) {
                return f.getName().toLowerCase().endsWith(".txt")
                        || f.isDirectory();
            }

            public String getDescription() {
                return "txt file";
            }
        });

        int r = chooser.showOpenDialog(new JFrame());
        if (r == javax.swing.JFileChooser.APPROVE_OPTION) {
            // String name = chooser.getSelectedFile().getName();

            //System.out.println(name);
            cpu.memory.loadFromDisk(chooser.getSelectedFile());
            System.out.println(chooser.getSelectedFile().getName() + "  " + cpu.memory.getValue(0) + "  " + cpu.memory.getValue(1));
            initMemoryDisplay(page, dec);
            

        }
    }//GEN-LAST:event_importBtnMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelBtn;
    private javax.swing.JLabel elapsedLbl;
    private javax.swing.JButton exportBtn;
    private javax.swing.JButton importBtn;
    private javax.swing.JEditorPane jEditorPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JLabel memoryAddressChangerLabel;
    private javax.swing.JTextField memoryChangerTxtField;
    private javax.swing.JDialog memoryDialog;
    private javax.swing.JList memoryList;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JButton okBtn;
    private javax.swing.JComboBox pageCombo;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JTextField r0TxtField;
    private javax.swing.JTextField r10TxtField;
    private javax.swing.JTextField r11TxtField;
    private javax.swing.JTextField r12TxtField;
    private javax.swing.JTextField r13TxtField;
    private javax.swing.JTextField r14TxtField;
    private javax.swing.JTextField r15TxtField;
    private javax.swing.JTextField r1TxtField;
    private javax.swing.JTextField r2TxtField;
    private javax.swing.JTextField r3TxtField;
    private javax.swing.JTextField r4TxtField;
    private javax.swing.JTextField r5TxtField;
    private javax.swing.JTextField r6TxtField;
    private javax.swing.JTextField r7TxtField;
    private javax.swing.JTextField r8TxtField;
    private javax.swing.JTextField r9TxtField;
    private javax.swing.JComboBox representationCombo;
    private javax.swing.JButton resetBtn;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JButton stepOneBtn;
    // End of variables declaration//GEN-END:variables
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;
}
